package Java.多线程.线程池;


public class InternalTask implements Runnable {

    private final MyTaskQueue<Runnable> myTaskQueue;

    private volatile boolean running = true;

    public InternalTask(MyTaskQueue<Runnable> myTaskQueue) {
        this.myTaskQueue = myTaskQueue;
    }

    @Override
    public void run() {
        while (running && !Thread.currentThread().isInterrupted()) {
            Runnable take = null;
            try {
                take = myTaskQueue.take();
                System.out.println("runnableQueue.take():" + take.toString());
                take.run();
            } catch (InterruptedException e) {
                running = false;
            }
        }
    }

    public void stop() {
        running = false;
    }
}
